package com.hamster.crmpre.web;

import com.hamster.crmpre.config.LoginInterceptor;
import com.hamster.crmpre.pojo.Customer;
import com.hamster.crmpre.pojo.Scheme;
import com.hamster.crmpre.pojo.SchemeConfig;
import com.hamster.crmpre.pojo.SchemeEmployee;
import com.hamster.crmpre.service.SchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 方案执行率的Controller
 * @author Tarry
 * @create 2019/12/31 11:28
 */
@RestController
@RequestMapping("scheme")
public class SchemeController {
    @Autowired
    private SchemeService schemeService;

    /**
     * 执行方案的列表
     * @return
     */
    @GetMapping("listSchemes")
    public ResponseEntity<List<Scheme>> listSchemes(){
        List<Scheme> list = schemeService.listSchemes();
        return ResponseEntity.ok(list);
    }

    /**
     * 查询执行方案的详细内容
     * @return
     */
    @GetMapping("getSchemeDetails")
    public ResponseEntity<SchemeEmployee> getSchemeDetails(@RequestParam String schemeId){
        String userId = LoginInterceptor.getLoginUser().getUserId();
        SchemeEmployee schemeDetails = schemeService.getSchemeDetails(userId, schemeId);

        return ResponseEntity.ok(schemeDetails);
    }

    /**
     * 获取选择自己客户的列表
     * @return
     */
    @GetMapping("listCustomers")
    public ResponseEntity<List<Customer>> listCustomers(){
        String userId = LoginInterceptor.getLoginUser().getUserId();
        List<Customer> listCustomers = schemeService.listCustomers(userId);
        return ResponseEntity.ok(listCustomers);
    }

    /**
     * 获取后台设置的配置比例
     * @return
     */
    @GetMapping("listConfig")
    public ResponseEntity<List<SchemeConfig>> listConfig(){
        List<SchemeConfig> schemeConfigs = schemeService.listConfig();
        return ResponseEntity.ok(schemeConfigs);
    }


    /**
     * 提交方案
     * @param schemeEmployee
     * @return
     */
    @PostMapping("insertScheme")
    public ResponseEntity<Void> insertScheme(@RequestBody SchemeEmployee schemeEmployee){
        schemeService.insertScheme(schemeEmployee);
        return ResponseEntity.ok().build();
    }




}
